﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Modelo.Interface;
namespace BL
{
    public class ServiceGeral
    {
        DalEntity.DalGeral _dalCliente;

        public ServiceGeral()
        {
            //_dalCliente = (IDalCliente)(Activator.CreateInstance(Properties.Settings.Default.Dal.Split('.')[0], Properties.Settings.Default.Dal + "." + "DalCliente")).Unwrap();
            _dalCliente = new DalEntity.DalGeral();    
        }
        
        public IList<T>  RetornarTodos<T>() where T : class,new()
        {
            try
            {
                return _dalCliente.RetornarGeral<T>();
            }
            catch (Exception ex)
            {
                Log.insertLog(ex.Message, " RetornarTodos " + (new T()).GetType().ToString(), "ServiceGeral" + (new T()).GetType().ToString());
                throw ex;
            }
         }
        
        public T RetornarPorID<T>(int id)  where T : class,new()
        {
            try
            {
                return _dalCliente.RetornarBasePorID<T>(id);
            }
            catch (Exception ex)
            {
                Log.insertLog(ex.Message, "RetornarPorID" + (new T()).GetType().ToString(), "ServiceGeral" + (new T()).GetType().ToString());
                throw ex;
            }
        }

        public bool Excluir<T>(int id)where T : class,new()
        {
            try
            {
                return _dalCliente.Excluir<T>(id);
            }
            catch (Exception ex)
            {
                Log.insertLog(ex.Message, "Excluir" + (new T()).GetType().ToString(), "ServiceGeral" + (new T()).GetType().ToString());
                return false;
            }
        }

        public bool Gravar<T>(T informacao) where T : class,new()
        {
            try
            {
                return _dalCliente.Inserir<T>(informacao);//InsereCliente(cliente);
            }
            catch (Exception ex)
            {
                Log.insertLog(ex.Message, "Gravar" + (informacao).GetType().ToString(), "ServiceGeral" + (new T()).GetType().ToString());

              return false;
            }
        }

        public bool Alterar<T>(T informacao) where T : class,new()
        {
            try
            {
                return _dalCliente.Alterar<T>(informacao);//InsereCliente(cliente);
            }
            catch (Exception ex)
            {
                Log.insertLog(ex.Message, "Alterar" + informacao.GetType().ToString(), "ServiceGeral" + informacao.GetType().ToString());
                return false;
            }
        
        }
    }
}
